package auth

import (
	"embed"
	"iris-wms/common/pkg/icasbin"
	"iris-wms/common/tools"
)

func InitAuth(conf embed.FS) {
	bytes, _ := conf.ReadFile("conf/rule_model.conf")
	icasbin.InitCasbin(tools.GConfig.App.Casbin.Tenant, string(bytes))
	icasbin.GCasbin.AddFunction("myFunc", MyFunc)
}
func MyFunc(args ...interface{}) (interface{}, error) {
	match := func(key string) bool {
		if key == "/api/admin/user/login" || key == "/api/admin/user/logout" ||
			key == "/api/admin/user/getUserInfo" || key == "/api/admin/user/own/reset_info" || key == "/api/admin/user/own/reset_password" ||
			key == "/api/admin/menu/ownList" {
			return true
		}
		return false
	}(args[0].(string))
	return (bool)(match), nil
}
